/*
 * @Description: 
 * @Author: Jinzhu Liu
 * @Date: 2021-11-24 18:07:22
 * @LastEditor: Jinzhu Liu
 * @LastEditTime: 2021-12-22 23:55:18
 */
import dotenv from 'dotenv'
dotenv.config()
  
import db from './db'
db()
import Koa from 'koa'
import bodyParser from 'koa-bodyparser'
import router from './router'
import { Server } from 'http'
import AccessLogMiddleware from './middleware/access_log_middleware'
import koaBody from 'koa-body'
import KoaStatic from 'koa-static'
import path from 'path/posix'

const app = new Koa

app
.use(koaBody({
    multipart: true,
    formidable: {
        maxFileSize: 200 * 1024 * 1024
    }
}))
.use(KoaStatic(path.join(__dirname, '..', 'statics')))
.use(AccessLogMiddleware)
.use(bodyParser())
.use(router.routes())

const run = (port: any): Server => {
    return app.listen(port)
}

export default run